﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Quaack.Web.Controls
{
    public enum MessageType
    {
        Undefined = 0,
        NewMessage = 1,
        NewReaction = 2,
        Edit
    }

    public partial class ContentHolder : System.Web.UI.UserControl
    {
        public TextBox Content { get { return this.ContentText; } }
        public TextBox Message { get { return this.MessageText; } }
        public Button LeftButton { get { return this.ButtonLeft; } }
        public Button RightButton { get { return this.ButtonRight; } }
        public MessageType EditType { get { return _editType; } }


        private MessageType _editType;

        public void DisableEdit()
        {
            this.Message.Enabled = false;
            this.Message.Visible = false;
            this.Content.Enabled = false;

            _editType = MessageType.Undefined;
        }

        public void EnableEdit(MessageType type)
        {
            _editType = type;

            switch (type)
            {
                case MessageType.NewMessage:
                    {
                        this.Message.Enabled = true;
                        this.Message.Visible = true;
                        break;
                    }

                case MessageType.NewReaction:
                    {
                        this.Message.Enabled = true;
                        this.Message.Visible = true;
                        break;
                    }
                case MessageType.Edit:
                    {
                        this.Content.Enabled = true;
                        break;
                    }
                default:
                    {
                        

                        break;
                    }

            }
        }


        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Page.RegisterRequiresControlState(this);
        }

        protected override object SaveControlState()
        {
            object obj = base.SaveControlState();

            if (obj != null)
            {
                return new Pair(obj, _editType);
            }
            else
            {
                return (_editType);
            }


        }

        protected override void LoadControlState(object state)
        {
            if (state != null)
            {

                if (state is MessageType)
                {
                    _editType = (MessageType)state;
                }
                else
                {
                    base.LoadControlState(state);
                }

            }
        }

    }
}